<?php

$idEvents = array(); //Array avec les id des évènement courants
$idSalle = array(); //Array avec les id des salles
$nomevent = array(); //Array avec les id des salles
$nomsalle= array(); //Array avec les id des salles
$index = 0;

//Récupère les derniers évènements
$mesvals = getLastEvents(3);

//Récupère que les id
while ($row = mysql_fetch_array($mesvals)) {
    $idEvents[$index] = $row[0];
    $idSalle[$index] = $row[14];
    $nomevent[$index] = $row[1];
    $nomsalle[$index] = $row['nomsalle'];
    $index++;
}

//Transforme et affiche les id des event en Array Javascript
echo TojsArray($idEvents,"idEvents");

//Transforme et affiche les id des salles en Array Javascript
echo TojsArray($idSalle,"idSalle");

//Fonction qui transforme un Array PHP en Array Javascript
function TojsArray($lc_values,$nom) {
    $script = "";

    $script = $script . "\n" . '<script type="text/javascript"> ' . "\nvar ".$nom." = new Array(";
    if (count($lc_values) > 1) {
        foreach ($lc_values as $key => $value) {
            if ($key < (count($lc_values) - 1)) {
                $script = $script . $value . ',';
            } else {
                $script = $script . $value . ");\n";
            }
        }
    } else {  // can't create an array that just has one integer element using Array()
        $script = $script . "1);\nlcValues[0]=" . $lc_values[0] . ";\n";
    }

    return $script . '</script>';
}
?>

<!--Script pour le rechargement automatique de la page après 5 min-->
<script type="text/JavaScript">
setTimeout("location.reload(true);",300000);
</script>

    <div>

        <a id="a2" data-rel="dialog" data-inline="true" data-transition="pop"/>
        <div id="div2" class="div_default_style" style="height: 97px; 
             width: 85px;
             left: 22px;
             top: 45px;" ></div></a>

    <a id="a1" data-rel="dialog" data-inline="true" data-transition="pop"/>
    <div id="div1" class="div_default_style" style="left: 138px; 
         top: 9px; 
         width: 58px; 
         height: 90px;"></div></a>

<a id="a4" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div4" class="div_default_style" style="top: 172px;
     height: 112px;
     left: 104px;
     width: 55px;" ></div></a>

<a id="a3" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div3" class="div_default_style" style="	left: 109px;
     top: 103px;
     width: 91px;
     height: 66px;" ></div></a>

<a id="a5" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div5" class="div_default_style" style="left: 163px;
     top: 205px;
     width: 94px;
     height: 81px;" ></div></a>

<a id="a6" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div6" class="div_default_style" style="left: 261px;
     top: 205px;
     width: 37px;
     height: 83px;" ></div></a>

<a id="a7" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div7" class="div_default_style" style="left: 203px;
     top: 103px;
     width: 94px;
     height: 100px;" ></div></a>

<a id="a9" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div9" class="div_default_style" style="left: 301px;
     top: 94px;
     width: 81px;
     height: 82px;" ></div></a>

<a id="a8" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div8" class="div_default_style" style="left: 301px;
     top: 179px;
     width: 74px;
     height: 107px;" ></div></a>

<a id="a12" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div id="div12" class="div_default_style" style="left: 378px;
     top: 179px;
     width: 51px;
     height: 110px;" ></div></a>

<a id="a13" data-rel="dialog" data-inline="true" data-transition="pop"/>
<div   id="div13" class="div_default_style" style="left: 412px;
       top: 80px;
       width: 71px;
       height: 88px;" ></div></a>




<img id="img1" src="../PlanChateau/Pictures/rez.png"  style="position:absolute; left: 1px; top: 0px; z-index: 1;" usemap="#map1"/>

<map name="map1" id="mamap" >

    <area shape="poly" coords="21,42,110,42,110,141,67,141,21,140"  />
    <area name="chambreDeSoleil" shape="rect" coords="103,171,158,284"   alt="chambre de soleil" />
    <area name="salleAManger" shape="rect" coords="160,204,258,284"   alt="salle à manger" />      
    <area name="bibliotheque" shape="rect" coords="259,204,297,284"  alt="bibliothèque" />
    <area name="salon" shape="rect" coords="299,179,374,284"   alt="salon"/>
    <area name="hall" shape="rect" coords="201,102,297,203"   alt="hall" />

    <area name="entree" shape="poly" coords="299,94,299,176,338,176,338,131,380,131,380,94"   alt="entrée" />
    <area name="veranda" shape="rect" coords="376,178,426,289" alt="veranda" />
    <area name="bureau" shape="rect" coords="410,80,481,167" alt="bureau" />
    <area name="office" shape="poly" coords="198,202,160,202,161,169,106,169,107,102,197,102"  alt="office" />
    <area name="perron" shape="poly" coords="158,9,158,65,136,65,136,99,195,99,195,65,190,63,190,9"  alt="perron de service" />
</map>

<script  LANGUAGE="JavaScript" >
            
  //Fonction appelée au chargeemnt de la page.
  //Va activer les bonnes zones et modifier les href
    function LoadEvent()
    {    
        for (i=0;i<idSalle.length;i++)
        {
            activateZone(idSalle[i], idEvents[i]);
        }
    }
        
    function activateZone(idsale, idevent) {
        var zone = document.getElementById('div' + idsale);
        var link = document.getElementById('a' + idsale);
   
        zone.style.visibility = "visible";

        link.href += '/Rilke/PlanChateau/dialogTest.php?id=' + idevent;

       
        return;
        
    }
    window.onload = LoadEvent;
</script>
</div>

<div style="margin-top: 332px; " >
      
<?php
           echo "<ul class='ui-listview' data-split-theme='d' data-split-icon='gear' data-role='listview'>";
           
      for($i = 0 ; $i <sizeof($nomsalle); $i++){

                                echo "<li class='ui-btn ui-btn-icon-right ui-li-has-arrow ui-corner-top ui-btn-up-c ui-li-has-count' data-theme='c'>\n";
                                echo "<div class='ui-li' aria-hidden='true'>\n";
                                echo "<div class='ui-btn-text'>\n";
                               
                                echo "<a class='ui-link-inherit' id='linkEvenement' data-rel='dialog' href='/Rilke/PlanChateau/dialogTest.php?id=". $idEvents[$i]."'>\n";
                                echo htmlentities(mysql_escape_string($nomevent[$i]));
                                echo "<span class='ui-li-count ui-btn-up-c ui-btn-corner-all' id='timeEvenement'>" .$idSalle[$i]." ". $nomsalle[$i] . "</span>";
                                echo "<p class='ui-li-desc'><br/></p>";
                                echo "</a></div></div></li>";
 
                    }
                     echo "</ul>";

?> 
     
   
     </div>



